home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / c / TinyGL.lha / tinygl / examples / lesson3.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-28  |  3.3 KB  |  87 lines

  1. /*
  2. When creating your project, uncheck OWL,
  3. uncheck Class Library, select Static
  4. instead of Dynamic and change the target
  5. model to Console from GUI.
  6. Also link glut.lib to your project once its done.
  7. */
  8.  
  9. #include <gl/gl.h>     // The GL Header File
  10. #include <gl/glut.h>   // The GL Utility Toolkit (Glut) Header
  11.  
  12. void init ( GLvoid )     // Create Some Everyday Functions
  13. {
  14.  
  15.   glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
  16.     glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                // Black Background
  17.     glClearDepth(1.0f);                                    // Depth Buffer Setup
  18.     glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
  19.     //glDepthFunc(GL_LEQUAL);                                // The Type Of Depth Testing To Do
  20.     glEnable ( GL_COLOR_MATERIAL );
  21.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  22. }
  23.  
  24. void display ( void )   // Create The Display Function
  25. {
  26.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear Screen And Depth Buffer
  27.     glLoadIdentity();                                    // Reset The Current Modelview Matrix
  28.     glTranslatef(-1.5f,0.0f,-6.0f);                        // Move Left 1.5 Units And Into The Screen 6.0
  29.     glBegin(GL_TRIANGLES);                                // Drawing Using Triangles
  30.         glColor3f(1.0f,0.0f,0.0f);                        // Set The Color To Red
  31.         glVertex3f( 0.0f, 1.0f, 0.0f);                    // Top
  32.         glColor3f(0.0f,1.0f,0.0f);                        // Set The Color To Green
  33.         glVertex3f(-1.0f,-1.0f, 0.0f);                    // Bottom Left
  34.         glColor3f(0.0f,0.0f,1.0f);                        // Set The Color To Blue
  35.         glVertex3f( 1.0f,-1.0f, 0.0f);                    // Bottom Right
  36.     glEnd();                                            // Finished Drawing The Triangle
  37.     glTranslatef(3.0f,0.0f,0.0f);                        // Move Right 3 Units
  38.     glColor3f(0.5f,0.5f,1.0f);                            // Set The Color To Blue One Time Only
  39.     glBegin(GL_QUADS);                                    // Draw A Quad
  40.         glVertex3f(-1.0f, 1.0f, 0.0f);                    // Top Left
  41.         glVertex3f( 1.0f, 1.0f, 0.0f);                    // Top Right
  42.         glVertex3f( 1.0f,-1.0f, 0.0f);                    // Bottom Right
  43.         glVertex3f(-1.0f,-1.0f, 0.0f);                    // Bottom Left
  44.     glEnd();                                            // Done Drawing The Quad
  45.  
  46.  
  47.   glutSwapBuffers ( );
  48.   // Swap The Buffers To Not Be Left With A Clear Screen
  49. }
  50.  
  51. void reshape ( int w, int h )   // Create The Reshape Function (the viewport)
  52. {
  53.     GLfloat  hw = (GLfloat) h / (GLfloat) w;
  54.  
  55.   glViewport     ( 0, 0, w, h );
  56.   glMatrixMode   ( GL_PROJECTION );  // Select The Projection Matrix
  57.   glLoadIdentity ( );                // Reset The Projection Matrix
  58.     
  59.     glFrustum( -1.0, 1.0, -hw, hw, 2.0, 60.0 );
  60.  
  61.     /*
  62.     if ( h==0 )  // Calculate The Aspect Ratio Of The Window
  63.      gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
  64.   else
  65.      gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
  66.     */
  67.   glMatrixMode   ( GL_MODELVIEW );  // Select The Model View Matrix
  68.   glLoadIdentity ( );    // Reset The Model View Matrix
  69. }
  70.  
  71. int main ( int argc, char** argv )   // Create Main Function For Bringing It All Together
  72. {
  73.   glutInit            ( &argc, argv ); // Erm Just Write It =)
  74.   glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode
  75.     glutInitWindowSize  ( 320, 256 ); // If glutFullScreen wasn't called this is the window size
  76.   glutCreateWindow    ( "NeHe's OpenGL Framework" ); // Window Title (argv[0] for current directory as title)
  77.     init();
  78.   glutDisplayFunc     ( display );  // Matching Earlier Functions To Their Counterparts
  79.   glutReshapeFunc     ( reshape );
  80.     reshape(320, 256);
  81.     display();
  82.   glutMainLoop        ( );          // Initialize The Main Loop
  83.     
  84.     return 0;
  85. }
  86.  
  87.